﻿// License: https://opensource.org/licenses/MIT
// Create Date : 2018-01-01

using System;

namespace Cat.Core.XLog
{
    /// <summary>
    /// ILogger默认实现（5个抽象接口）
    /// </summary>
    public abstract partial class LoggerBase0 : ILogger, ILogSwitch
    {
        LogStringFormator _logStringFormator = new LogStringFormator();

        #region ILogSwitch 实现
        bool _isDebugEnabled = true;
        bool _isInfoEnabled = true;
        bool _isWarnEnabled = true;
        bool _isErrorEnabled = true;
        bool _isFatalEnabled = true;
        public bool IsDebugEnabled { get { return _isDebugEnabled; } }
        public bool IsInfoEnabled { get { return _isInfoEnabled; } }
        public bool IsWarnEnabled { get { return _isWarnEnabled; } }
        public bool IsErrorEnabled { get { return _isErrorEnabled; } }
        public bool IsFatalEnabled { get { return _isFatalEnabled; } }
        public virtual void SetIsDebugEnabled(bool enable) { _isDebugEnabled = enable; }
        public virtual void SetIsInfoEnabled(bool enable) { _isInfoEnabled = enable; }
        public virtual void SetIsWarnEnabled(bool enable) { _isWarnEnabled = enable; }
        public virtual void SetIsErrorEnabled(bool enable) { _isErrorEnabled = enable; }
        public virtual void SetIsFatalEnabled(bool enable) { _isFatalEnabled = enable; }
        #endregion

        #region 抽象接口
        protected abstract void Debug(Exception exception, Lazy<string> message);
        protected abstract void Info(Exception exception, Lazy<string> message);
        protected abstract void Warn(Exception exception, Lazy<string> message);
        protected abstract void Error(Exception exception, Lazy<string> message);
        protected abstract void Fatal(Exception exception, Lazy<string> message);
        #endregion
    }

    /// <summary>
    /// ILogger默认实现（1个抽象接口）
    /// </summary>
    public abstract class LoggerBase : LoggerBase0, ILogger
    {
        protected abstract void Log(LogLevel level, Exception exception, Lazy<string> message);

        protected override void Debug(Exception exception, Lazy<string> message) { Log(LogLevel.Debug, exception, message); }
        protected override void Info(Exception exception, Lazy<string> message) { Log(LogLevel.Info, exception, message); }
        protected override void Warn(Exception exception, Lazy<string> message) { Log(LogLevel.Warn, exception, message); }
        protected override void Error(Exception exception, Lazy<string> message) { Log(LogLevel.Error, exception, message); }
        protected override void Fatal(Exception exception, Lazy<string> message) { Log(LogLevel.Fatal, exception, message); }
    }
}
